import { createRequest } from './request'
import {
  baseRequestInterceptor,
  resultResponseInterceptor,
  statusResponseInterceptor,
  tokenRequestInterceptor,
} from './interceptors'
import { getServiceEnvConfig } from '@/config'

const { url } = getServiceEnvConfig(import.meta.env)
/**
 * 未登录请求
 */
export const freeRequest = createRequest(
  {
    baseURL: url,
  },
  {
    requestInterceptors: [baseRequestInterceptor],
    responseInterceptors: [statusResponseInterceptor, resultResponseInterceptor],
  },
)
/**
 * 登录后请求
 */
export const authResquest = createRequest(
  {
    baseURL: url,
  },
  {
    requestInterceptors: [baseRequestInterceptor, tokenRequestInterceptor],
    responseInterceptors: [statusResponseInterceptor, resultResponseInterceptor],
  },
)
